var UIController = require("UIController");

var LevelManager = cc.Class({
    extends: cc.Component,

    properties: {
        gameActive: cc.Boolean,
		timer: cc.Float,
    },

	statics: {
		instance: null,
	},
	ctor() {
		LevelManager.instance = this;
	},

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},

    start () {
		this.gameActive = true;
    },

    update (dt) {
		if (this.gameActive == true) {
			this.timer += dt;
			UIController.instance.updateTimer(this.timer);
		}
	},

	endLevel () {
		this.gameActive = false;

		setTimeout(() => {
			let Timer = Math.round(this.timer);
			let minutes = Math.floor(Timer / 60);
			let seconds = Timer % 60;
			if (seconds < 10) {
				seconds = "0" + seconds;
			}

			UIController.instance.endTimeLabel.string = minutes + ":" + seconds;
			UIController.instance.levelEndScreen.active = true;
		}, 1000);

	},

	
});

module.exports = LevelManager;
